//
//  UserBlackListCell.m
//  CheekiOS
//
//  Created by mac on 2017/6/23.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserBlackListCell.h"
@interface UserBlackListCell ()

@property (nonatomic, strong)UIImageView *imgView ;
@property (nonatomic, strong)UILabel *nameLab;
@property (nonatomic, strong)UILabel *numberLab;
@property (nonatomic, strong)UIButton *btndelete;
@property (nonatomic, strong)UILabel *linlab;
@property (nonatomic, assign)NSIndexPath *indexPath;

@end

@implementation UserBlackListCell

+ (instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath*)indexPath {
    static NSString *UserBlackListCellIdent = @"UserBlackListCellIdent";
    UserBlackListCell *cell = [tableView dequeueReusableCellWithIdentifier:UserBlackListCellIdent];
    if (!cell) {
        cell = [[UserBlackListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UserBlackListCellIdent];
    }
    cell.indexPath = indexPath;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;

}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.imgView = [[UIImageView alloc]init];
        [self.imgView.layer setMasksToBounds:YES];

        [self addSubview:self.imgView];
        
        self.nameLab = [[UILabel alloc] init];
        self.nameLab.textColor = [UIColor blackColor];
        self.nameLab.font =FontP(15);
        self.nameLab.textAlignment =NSTextAlignmentLeft;
        [self addSubview:self.nameLab];
        
        self.numberLab = [[UILabel alloc] init];
        self.numberLab.textColor = RGB(200, 200, 200);
        self.numberLab.font = FontP(15);
        self.numberLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.numberLab];
        
        self.btndelete = [UIButton buttonWithType:UIButtonTypeCustom];
        self.btndelete.backgroundColor = Colorbackground;
        [self.btndelete setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.btndelete.layer.cornerRadius=15;
        self.btndelete.titleLabel.font = FontP(15);
   
        [self addSubview:self.btndelete];

        
        self.linlab = [UILabel new];
        self.linlab.backgroundColor = RGB(243, 243, 243);
        [self addSubview:self.linlab];
        
        [self layoutdata];
    }
    return self;
}

- (void)layoutdata{
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.top.equalTo(self).offset(12);
        make.width.height.mas_equalTo(50);
    }];
    
    self.imgView.layer.cornerRadius = 25;
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(15);
        make.top.equalTo(self).offset(8);
        make.height.mas_equalTo(30);
    }];
    
    [self.numberLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).offset(15);
        make.top.equalTo(self.nameLab.mas_bottom).offset(8);
        make.height.mas_equalTo(30);
    }];
    
    
    [self.btndelete mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self).offset(22);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(60);
        
    }];
    
    [self.linlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.equalTo(self);
        make.top.equalTo(self.mas_bottom).offset(1);
        make.height.mas_equalTo(1);
        
    }];
}


-(void)setModel:(NSDictionary *)model{
    
   
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(model[@"photo"])] placeholderImage:[UIImage imageNamed:@"llustration"]];
    [self.btndelete setTitle:@"移除" forState:UIControlStateNormal];
    self.nameLab.text = model[@"nickName"];
    self.numberLab.text = [NSString stringWithFormat:@"ID：%@",model[@"wid"]] ;
    
    self.btndelete.tag = _indexPath.row;
    [self.btndelete addTarget:self action:@selector(btndeleteClick:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)btndeleteClick:(UIButton *)sender{

    if ([self.delegate respondsToSelector:@selector(BtnDelegateClick:)]) {
        [self.delegate BtnDelegateClick:sender];
    }

}


@end
